import request from "@/utils/request.ts";
import {LoginData, RegisterData, ReturnDataSingle, UserInfo} from "@/api/types/user.ts";

export const registerUser = (registerData:RegisterData) => {
    return request<UserInfo>(
        {
            url: '/api/user/register',
            method: 'POST',
            headers: {
                'Content-Type': 'multipart/form-data'
            },
            data: {

                id: registerData.id,
                password: registerData.password,
                name: registerData.name,
                majority: registerData.majority,
                class_num: registerData.class_num,
                entry_year: registerData.entry_year,
                graduate_year: registerData.graduate_year,
                employers: registerData.employers,
                city: registerData.city,
                phone: registerData.phone,
                email: registerData.email
            },

        }
    )
}

export const loginUser = (loginData:LoginData) => {
    return request<UserInfo>(
        {
            url: '/api/user/login',
            method: 'GET',
            params: loginData
        }
    )
}

export const updateUser = (registerData:RegisterData) => {
    return request<UserInfo>(
        {
            url: '/api/user/update',
            method: 'POST',
            headers: {
                'Content-Type': 'multipart/form-data'
            },
            data: {
                id: registerData.id,
                password: registerData.password,
                name: registerData.name,
                majority: registerData.majority,
                classNum: registerData.class_num,
                entryYear: registerData.entry_year,
                graduateYear: registerData.graduate_year,
                employers: registerData.employers,
                city: registerData.city,
                phone: registerData.phone,
                email: registerData.email
            },

        }
    )
}

export const logoffUser = () => {
    return request(
        {
            url: '/api/user/logoff',
            method: 'GET',
        }
    )
}

export const userCenter = (id: string) => {
    return request<ReturnDataSingle> ({
        url: '/api/user/center',
        method: 'GET',
        params: {
            id: id
        }
    })
}

export const countByMajority = () => {
    return request ({
        url: '/api/contacts/count/majority',
        method: 'GET',
    })
}

export const countByCity = () => {
    return request ({
        url: '/api/contacts/count/city',
        method: 'GET',
    })
}



